package com.sskj.gocoin.v.activity;

import android.graphics.Color;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sskj.gocoin.BuildConfig;
import com.sskj.gocoin.R;
import com.sskj.gocoin.common.widget.ToolBarLayout;
import com.sskj.gocoin.m.HttpConfig;
import com.sskj.gocoin.p.activity.AboutUsPresenter;
import com.sskj.gocoin.v.base.BaseActivity;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import butterknife.BindView;

/**
 * <pre>
 *     author : 吕志豪
 *     e-mail : 1030753080@qq.com
 *     time   : 2018/04/03
 *     desc   :
 *     version: 1.0
 * </pre>
 */

public class AboutUsActivity extends BaseActivity<AboutUsPresenter> {
    @BindView(R.id.contract_us)
    LinearLayout rlContactUs;
    @BindView(R.id.toolBar)
    ToolBarLayout toolBar;
    @BindView(R.id.version)
    TextView versionName;


    @Override
    protected int getLayoutResId() {
        return R.layout.activity_about_us;
    }

    @Override
    public AboutUsPresenter getPresenter() {
        return new AboutUsPresenter();
    }

    @Override
    protected void onViewBinding() {
        versionName.setText("当前版本V" + BuildConfig.VERSION_NAME);
        if (BuildConfig.RELEASE) {//正式版
            versionName.setTextColor(getResources().getColor(R.color.color_orange));
        } else {//测试版
            versionName.setTextColor(Color.RED);
        }
//        mPresenter.getContent();
//        mPresenter.getEmail();
        toolBar.setLeftButtonOnClickLinster(v -> finish());
    }

    /**
     * 自定义布局
     * setView()只会覆盖AlertDialog的Title与Button之间的那部分，而setContentView()则会覆盖全部，
     * setContentView()必须放在show()的后面
     */
    public void setEmail(String emailStr) {
//        setText(email, emailStr);
    }

    public void setContent(String data) {
//        RichText.fromHtml(formatImg(data)).bind(this).into(content);
    }


    public String formatImg(String content) {
        Document document = Jsoup.parse(content);
        Elements imgs = document.getElementsByTag("img");
        for (int i = 0; i < imgs.size(); i++) {
            Element img = imgs.get(i);
            img.attr("width", "100%").attr("height", "auto");
            String url = img.attr("src");
            if (!url.contains("http")) {
                url = HttpConfig.BASE_URL + url;
            }
            img.attr("src", url);
        }
        return document.toString();
    }


}
